package oop4;

public class Company {
	private String name;
	private String add;
	Car jiaoche[] = new Car[6];
	Bus keche[] = new Bus[6];

	public Company() {
	}

	public void add(String ID, String brand, double price, int seat) {

		for (int i = 0; i < keche.length; i++) {
			if (keche[i].getID() != null) {
				keche[i] = new Bus(ID, brand, price, seat);

				keche[i].setWasRented(false);
				return;
			}
		}

	}

	public void add(String ID, String brand, double price, String type) {
		for (int i = 0; i < jiaoche.length; i++) {
			if (jiaoche[i].getID() == null) {
				jiaoche[i] = new Car(ID, brand, price, type);

				jiaoche[i].setWasRented(false);
				return;
			}
		}
	}

	public void delete(String brand, int seat) {
		int i, j;
		int count = 0;
		for (int k = 0; k < keche.length; k++)
			if (keche[k].getID() != null)
				count++;
		for (i = 0; i < count; i++)
			if (keche[i].getBrand() != null && keche[i].getBrand().equals(brand) && keche[i].getSeat() == seat) {
				// keche[i]=null;
				keche[i] = new Bus(null, null, 0, 0);

				for (j = i; j < count - 1; j++) {
					keche[j] = keche[j + 1];
				} // keche[keche.length-1]=null;

				keche[count - 1] = new Bus(null, null, 0, 0);

				return;

			}

	}

	public void delete(String brand, String type) {
		int count = 0;
		for (int k = 0; k < jiaoche.length; k++)
			if (jiaoche[k].getID() != null)
				count++;
		for (int i = 0; i < count; i++)
			if (jiaoche[i].getBrand() != null && jiaoche[i].getBrand().equals(brand) && jiaoche[i].getType() != null
					&& jiaoche[i].getType().equals(type)) {
				// jiaoche[i]=null;
				jiaoche[i] = new Car(null, null, 0, null);
				for (int j = i; j < count - 1; j++) {
					jiaoche[j] = jiaoche[j + 1];
				} // keche[keche.length-1]=null;
				jiaoche[count - 1] = new Car(null, null, 0, null);
				return;

			}
	}

	public void rent(String brand, int seat) {
		for (int i = 0; i < keche.length; i++) {
			if (keche[i].getBrand() != null && keche[i].getBrand().equals(brand) && keche[i].getSeat() == seat) {
				keche[i].setWasRented(true);
			}
		}
	}

	public void rent(String brand, String type) {
		for (int i = 0; i < jiaoche.length; i++) {
			if (jiaoche[i].getBrand() != null && jiaoche[i].getBrand().equals(brand) && jiaoche[i].getType() != null
					&& jiaoche[i].getType().equals(type)) {
				jiaoche[i].setWasRented(true);
			}
		}
	}

	public void giveBack(String brand, int seat) {
		for (int i = 0; i < keche.length; i++) {
			if (keche[i].getBrand() != null && keche[i].getBrand().equals(brand) && keche[i].getSeat() == seat) {
				keche[i].setWasRented(false);
			}
		}
	}

	public void giveBack(String brand, String type) {
		for (int i = 0; i < jiaoche.length; i++) {
			if (jiaoche[i].getBrand() != null && jiaoche[i].getBrand().equals(brand) && jiaoche[i].getType() != null
					&& jiaoche[i].getType().equals(type)) {
				jiaoche[i].setWasRented(false);
			}
		}
	}

	public Company(String name, String add) {
		this.name = name;
		this.add = add;
	}

	public double calcuDis(int d) {

		if (d >= 7 && d < 30)
			return 0.9;
		if (d >= 30 && d < 150)
			return 0.8;
		return 0.7;

	}

	public void showInfo() {
		System.out.print("序号\t" + "车辆信息\t\t" + "车牌号\t\t" + "租金\t" + "状态\n");
		for (int i = 0; i < jiaoche.length; i++) {

			if (jiaoche[i].getID() != null) {

				System.out.print((i + 1) + "\t" + jiaoche[i].getBrand() + jiaoche[i].getType() + "\t\t"
						+ jiaoche[i].getID() + "\t" + jiaoche[i].getPrice() + "\t" + jiaoche[i].getWasRented() + "\n");

			}
		}
		for (int i = 0; i < keche.length; i++) {
			if (keche[i].getID() != null) {

				System.out.print((i + 1) + "\t" + keche[i].getBrand() + keche[i].getSeat() + "\t\t" + keche[i].getID()
						+ "\t" + keche[i].getPrice() + "\t" + keche[i].getWasRented() + "\n");

			}

		}
	}

	public void inTo(Car car[]) {
		jiaoche = car;
	}

	public void inTo(Bus bus[]) {
		keche = bus;
	}
}
